--
-- Author: ping.wang
-- Date: 2018-08-02 17:48:11
--
-- NewguildSetIconRender
--

local ClassRef = app.mvc.createRenderClass(...)

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.NewGuildSetIconNode))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end


function ClassRef:init(data)
    self.super.init(self, data)
    self:setContentSize( self._ui.Panel:getContentSize() )
    self._ui.Panel:setSwallowTouches(false)
--[[
    local label = display.newTTFLabel({size = 14,align = cc.TEXT_ALIGNMENT_LEFT,valign=cc.TEXT_ALIGNMENT_LEFT})
    label:setColor(display.COLOR_RED)
    label:setPosition(self:getContentSize().width/2,self:getContentSize().height/2)
    self:addChild(label)
    self._text = label
--]]
    self:refresh()
end

function ClassRef:refresh()
    if self._data then
        self:setVisible( true )

        local data = self._data

        if data.baseIconId then
            local baseIconPath = GD:getImagePath( Res.guildIconPath, data.baseIconId )
            self._ui.icon_u:setVisible(true)
            self._ui.icon_u:loadTexture( baseIconPath )
        else
            self._ui.icon_u:setVisible(false)
        end

        if data.additionIconId then
            local additionalIconPath = GD:getImagePath( Res.guildIconPath, data.additionIconId )
            self._ui.icon_b:setVisible(true)
            self._ui.icon_b:loadTexture( additionalIconPath )
        else
            self._ui.icon_b:setVisible(false)
        end

        if data.baseIconColor then
            self._ui.icon_u:setColor( data.baseIconColor )
        end

        if data.additionIconColor then
            self._ui.icon_b:setColor( data.additionIconColor )
        end

        --self._text:setString(data.baseIconId)

        self:setVisible(true)
    else
        self:setVisible( false )
    end
end

function ClassRef:setSelected(bl)
    self._ui["Panel/selected"]:setVisible(bl)
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

function ClassRef:getData()
    return self._data
end

return ClassRef
